<!DOCTYPE html>
<html lang="en">
    <head>
            <meta charset="utf-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <meta content="Bmob,BmobCloud,bomb,BaaS,mBaaS,PaaS,Serverless,FaaS,Function as a Service,Backend as a Service,serverless computing,cloud function,后端云,bmob后端云,小程序云,小程序后端,云数据库,云存储,文件存储,云函数,云端代码,定时任务,游戏后端,游戏云,用户系统,无服务器函数,移动开发,app开发,小程序开发,云端一体化,互联网中间件" name="keywords"/>
            <meta content="国内首家专注于移动应用Serverless云服务的平台,Bmob后端云让移动开发更简单,全方位一体化的后端服务平台" name="description"/>
            
            
            
            <link rel="shortcut icon" href="../../../img/favicon.ico">
        
        <script type="text/javascript" src="//game.bmob.cn/static/doc_union.js"></script>
            <!--
            <title>开发文档 - Bmob文档中心</title>
            -->
            <title>数据存储 &middot; GO – Bmob后端云 </title>        
            
            <link href="../../../css/bootstrap-custom.min.css" rel="stylesheet">
            <link href="../../../css/font-awesome-4.5.0.css" rel="stylesheet">
            <link href="../../../css/base.css" rel="stylesheet">
            <link rel="stylesheet" href="../../../css/highlight.css">
            <link href="../../../css/agate.css" rel="stylesheet">
            <link href="../../../css/custom.css" rel="stylesheet" id="custom">
    </head>

    <body >

        <div class="navbar navbar-fixed-top" role="navigation">
    <div class="main-nav">
        <!-- Collapsed navigation -->
        <div class="navbar-header">
            <a class="navbar-brand" href="../../..">
                <!--Bmob文档中心-->
                <img src="../../../img/logo.png" alt="">
            </a>
        </div>

        <!-- Expanded navigation -->
        <div class="navbar-collapse collapse">

          <ul class="nav navbar-nav">
            
              <li class="pull-left">
                
					<a href="../../..">文档首页</a>
                
              </li>
            
              <li class="pull-left active">
                
					<!--<a href="">数据服务</a>-->
					<li class="dropdown active">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">数据服务 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
								<li >
									<a href="../../android/">Android</a>
                                </li>
                            
                            
								<li >
									<a href="../../ios/">iOS</a>
                                </li>
                            
                            
								<li >
									<a href="../../csharp/">C#</a>
                                </li>
                            
                            
								<li >
									<a href="../../php/">PHP</a>
                                </li>
                            
                            
								<li class="active">
									<a href="../">GO</a>
                                </li>
                            
                            
								<li >
									<a href="../../restful/">REST API</a>
                                </li>
                            
                            
								<li >
									<a href="../../wechat_app_new/rm/">JavaScript</a>
                                </li>
                            
                            
                                <li >
                                    <a href="../../cocos2d_x/">Cocos2D-X</a>
                                </li>
							
                            
								<li >
									<a href="../../wechat_app/">小程序</a>
                                </li>
                            
                            
                                <li >
                                    <a href="../../wechat_app_new/">快应用</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../wechat_app_new/">Nodejs</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../wechat_app_new/">Cocos Creator</a>
                                </li>
							
                            
								<li >
									<a href="../../wechat_app_new/rm/">小程序(新)</a>
                                </li>
                            
                            
                                <li >
                                    <a href="../../kotlin/">Kotlin</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../python/">Python</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="../../../cloud_function/android/">云函数</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">云函数 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
                                <li >
                                    <a href="../../../cloud_function/android/">Android</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/ios/">iOS</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/java/">Java</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/python/">Python</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/csharp/">C#</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/php/">PHP</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/javascript/">JavaScript</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/restful/">REST API</a>
                                </li>
							
                            
								<li >
									<a href="../../../cloud_function/web/">Web</a>
                                </li>
                            
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="../../../sms/android/">短信服务</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">短信服务 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
                                <li >
                                    <a href="../../../sms/android/">Android</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../sms/ios/">iOS</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../sms/php/">PHP</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../sms/javascript/">JavaScript</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../sms/restful/">REST API</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="">游戏实时后端</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">游戏实时后端 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
								<li >
									<a href="../../../game/unity/quick_start/">Unity</a>
                                </li>
                            
                            
								<li >
									<a href="../../../game/cocos_creator/quick_start/">Cocos Creator</a>
                                </li>
                            
                            
								<li >
									<a href="../../../game/wechat_games/quick_start/">微信小游戏</a>
                                </li>
                            
                            
                                <li >
                                    <a href="../../../game/cloud_function/develop_doc/">云函数</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../game/classic_case/">经典案例</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="">即时通讯</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">即时通讯 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
								<li >
									<a href="../../../im/android/">Android</a>
                                </li>
                            
                            
								<li >
									<a href="../../../im/ios/">iOS</a>
                                </li>
                            
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="../../../push/android/">推送服务</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">推送服务 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
                                <li >
                                    <a href="../../../push/android/">Android</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../push/ios/">iOS</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../push/php/">PHP</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../push/javascript/">JavaScript</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../push/restful/">REST API</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="../../../other/common_problem/">其他</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">其他 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
                                <li >
                                    <a href="../../../other/common_problem/">常见问题</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../other/error_code/">错误码</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../other/data_safety/">数据安全</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../other/bql/">BQL</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li>
                  <a href="https://www.bmob.cn/repository/index" target="_blank">知识库</a>
              </li>
              <li>
                  <a href="http://doc.bmob.cn/video/index.html" target="_blank">视频教程</a>
              </li>
            </ul>
            
        </div>
    </div>
</div>

        <div class="pagebody" id="main-wrapper">
            <div class="sidebar">
                <div class="bs-sidebar hidden-print affix well" role="complementary">

	
		
	
		
				
				
				
				
				
					<div class="code-title">GO</div>
				
				
				
				
				
				
				
				
				
				
				
		
	
		
				
				
				
				
				
				
				
				
				
		
	
		
				
				
				
				
				
		
	
		
				
				
				
				
				
		
	
		
				
				
		
	
		
				
				
				
				
				
		
	
		
				
				
				
				
		
	


	<ul class="nav bs-sidenav">
		
			
		
			
				
					
						
					
						
					
						
					
						
					
						
							
								
									<li class="">
										<a class="itm-l1" href="../">快速入门</a>
										
									</li>
								
									<li class="active">
										<a class="itm-l1" href="./">开发文档</a>
										
										<ul class="nav">
											
											<li class="active "><a href="#_1">简介</a>
												
											</li>
												
											<li class=""><a href="#_2">快速入门</a>
												
											</li>
												
											<li class=""><a href="#_3">应用程序</a>
												
											</li>
												
											<li class=""><a href="#_4">应用安全</a>
												
											</li>
												
											<li class=""><a href="#_5">数据类型</a>
												
											</li>
												
											<li class=""><a href="#rest-api">REST API请求</a>
												
											</li>
												
											<li class=""><a href="#_6">数据对象</a>
												
											</li>
												
										</ul>
										
									</li>
								
							
						
					
						
					
						
					
						
					
						
					
						
					
						
					
						
					
						
					
						
					
						
					
				
			
		
			
		
			
		
			
		
			
		
			
		
			
		
	</ul>
</div>
            </div>
            <div class="content" role="main">
                <div class="wrap">
                    

<h2 id="_1">简介<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h2>
<p>Bmob平台为您的移动应用提供了一个完整的后端解决方案，我们提供轻量级的SDK开发包，让开发者以最小的配置和最简单的方式使用Bmob平台提供的服务，进而完全消除开发者编写服务器代码以及维护服务器的操作。
Go SDK封装了Bmob REST API API，但并不包含功能封装，如果需要调用具体的功能，请参考官方REST API API开发文档<a href="http://docs.bmob.cn/data/Restful/b_developdoc/doc/index.html">http://docs.bmob.cn/data/Restful/b_developdoc/doc/index.html</a></p>
<h2 id="_2">快速入门<a class="headerlink" href="#_2" title="Permanent link">&para;</a></h2>
<p>建议您在阅读本开发文档之前，先阅读我们提供的 <a href="https://github.com/bmob/bmob-go-sdk/tree/master/doc_quickstart">go快速入门文档</a>，便于您后续的开发。</p>
<h2 id="_3">应用程序<a class="headerlink" href="#_3" title="Permanent link">&para;</a></h2>
<p>在Bmob平台注册后，每个账户可创建多个应用程序，创建的每个应用程序有各自的Application ID，应用程序将凭其Application ID使用Bmob SDK。</p>
<h2 id="_4">应用安全<a class="headerlink" href="#_4" title="Permanent link">&para;</a></h2>
<p>请大家在使用Bmob开发应用程序之前，仔细阅读“数据与安全”的文档：<a href="http://docs.bmob.cn/other/Other/m_bql/doc/index.html">http://docs.bmob.cn/other/Other/m_bql/doc/index.html</a></p>
<h2 id="_5">数据类型<a class="headerlink" href="#_5" title="Permanent link">&para;</a></h2>
<p>除了JSON标准里定义的数据类型外，还支持Bmob自定义的数据类型：<a href="http://docs.bmob.cn/data/Restful/b_developdoc/doc/index.html#对象">http://docs.bmob.cn/data/Restful/b_developdoc/doc/index.html#对象</a>
这些类型操作相关的基本数据结构在types.go中定义，由于JSON是schema-less的，你可以只填充必要的字段来完成操作</p>
<h2 id="rest-api">REST API请求<a class="headerlink" href="#rest-api" title="Permanent link">&para;</a></h2>
<p>一次典型的REST API请求如下：</p>
<pre><code>  header, err := bmob.DoRestReq(appConfig,
    bmob.RestRequest{
      bmob.BaseReq{
        &quot;GET&quot;,
        bmob.ApiRestURL(&quot;GameScore&quot;) + &quot;/&quot;,
        &quot;&quot;},
      &quot;application/json&quot;,
      nil},
    &amp;respDst}
  if err == nil {
    log.Println(header}
    log.Println(respDst}
  } else {
    log.Panic(err}
  }
</code></pre>

<p>参数：
<em> appConfig - 保存了APP相关的key等信息
</em> RestRequest - 使用Bmob REST API API 所需的信息： {方法， url， sessionToken}， 数据类型， body
<em> respDst - 用于保存解析后的response
返回值：
</em> header - http.Header， 请求返回的标准HTTP头
* err - 错误信息</p>
<pre><code>curl -X GET \
    -H &quot;X-Bmob-Application-Id: Your Application ID&quot; \
    -H &quot;X-Bmob-REST-API-Key: Your REST API Key&quot; \
    -G \
    --data-urlencode 'where={&quot;createdAt&quot;:{&quot;$gte&quot;:{&quot;__type&quot;:&quot;Date&quot;,&quot;iso&quot;:&quot;2011-08-21 18:02:52&quot;}}}' \
    https://api2.bmob.cn/1/classes/GameScore
</code></pre>

<p>再一次请求中，你需要指定的HTTP方法，URL，sessionToken等均可以在BaseReq中指定，
APP验证需要的KEY等在RestConfig中指定
数据段则在转成[]byte类型后传入
上传不同类型的格式时，需要指定编码格式，默认为text/plain，</p>
<h2 id="_6">数据对象<a class="headerlink" href="#_6" title="Permanent link">&para;</a></h2>
<p>Bmob请求格式化数据时，body为JSON格式，用户可以自定义需要的字段，但是由于返回的数据会附加Bmob预定义的字段，所以需要单独处理。 SDK中采取的写法如下：</p>
<pre><code>type TestDataType struct {
  Score string
  data  DataType
}

type TestDataRes struct {
  TestData
  bmob.RestResponse
}
</code></pre>

<p>通过继承自定义的Response结构体，我们可以同时解析返回的数据里的用户定义数据和系统定义数据。</p>
<p>RestResponse包含了解析最常用的请求响应所需的字段，如果需要其他解析其他请求的响应，可以继承SDK中提供的相应的结构体，如ImageResponse</p>
<pre><code>type MyRes struct {
  bmob.RestResponse
  bmob.ImageResponse
}
</code></pre>

<p>这个结构体可以解析标准的REST API响应和Image请求相关的响应</p>
                </div>
            </div>
        </div>

        
            <script>var base_url = '../../..';</script>
            <script src="../../../js/jquery-1.10.2.min.js"></script>
            <script src="../../../js/bootstrap-3.0.3.min.js"></script>
            <script src="../../../js/highlight.pack.js"></script>
            <script src="../../../js/main.js"></script>
            <script src="../../../js/base.js"></script>

        <div id="go-top"><i class="fa fa-chevron-up"></i></div>
        <a href="https://docs.bmob.cn/data/Android/a_faststart/doc/index.html" id="back" target="_blank">返回 <br> 旧版</a>
    </body>

</html>